package com.wxzz.elearing.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxzz.elearing.user.entity.WxUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Optional;

public interface WxUserMapper extends BaseMapper<WxUser> {

    @Select("SELECT * FROM wx_user WHERE openid = #{openid} AND deleted = 0")
    Optional<WxUser> selectWxUserByOpenid(@Param("openid") String openid);

    @Select("SELECT * FROM wx_user WHERE phone = #{phone} AND openid IS NOT NULL AND deleted = 0")
    Optional<WxUser> selectWxUserByPhoneAndOpenidIsNotNull(@Param("phone")String phone);

    @Select("SELECT * FROM wx_user WHERE phone = #{phone} AND openid IS NULL AND deleted = 0")
    Optional<WxUser> selectWxUserByPhoneAndOpenidIsNull(@Param("phone")String phone);

    @Select("SELECT * FROM `wx_user` WHERE phone = #{phone} AND deleted = 0")
    Optional<WxUser>  selectWxUserByPhone(@Param("phone")String phone);
}
